package com.one.controller;


import com.one.dto.Result;
import com.one.entity.SysCollegeEntity;
import com.one.entity.SysUserEntity;
import com.one.service.SysCollegeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-10-05
 */
@RestController
@RequestMapping("/college")
public class SysCollegeController {
    private final SysCollegeService sysCollegeService;
    public SysCollegeController(SysCollegeService sysCollegeService) {
        this.sysCollegeService=sysCollegeService;
    }
    //添加学院
    @ApiOperation(value = "增加学院", notes = "增加学院")
    @PostMapping("/insertCollege")
    public Result insertCollege(@RequestBody(required = false) SysCollegeEntity sysCollegeEntity){
        if(selectCollegeByCodeAndName(sysCollegeEntity).getData()!=null){
            return Result.error().message("该学院已经存在了");
        }
        return sysCollegeService.insertCollege(sysCollegeEntity);
    }
    //根据学院标号和名称查询学院
    @ApiOperation(value = "根据学院标号和名称查询学院", notes = "根据学院标号和名称查询学院")
    @PostMapping("/selectCollegeByCodeAndName")
    public Result selectCollegeByCodeAndName(@RequestBody(required = false) SysCollegeEntity sysCollegeEntity){
        return sysCollegeService.selectCollegeByCodeAndName(sysCollegeEntity);
    }
    //删除学院
    @ApiOperation(value = "删除学院", notes = "删除学院")
    @PostMapping("/deleteCollege")
    public Result deleteCollege(@RequestBody(required = false) SysCollegeEntity sysCollegeEntity){
        if (sysCollegeEntity.getCode()==null){
            return Result.error().message("学院的编号不能为空");
        }
        return sysCollegeService.deleteCollege(sysCollegeEntity);
    }
    //修改学院信息
    @ApiOperation(value = "修改学院信息",notes = "修改学院信息")
    @PostMapping("/updateCollege")
    public Result updateCollege(@RequestBody(required = false) SysCollegeEntity sysCollegeEntity){
        return sysCollegeService.updateCollege(sysCollegeEntity);
    }
    //查询学院的信息
    @ApiOperation(value = "查询学院的信息", notes = "查询学院的信息")
    @PostMapping("/selectCollege")
    public Result selectCollege(@RequestBody(required = false) SysCollegeEntity sysCollegeEntity){
        return sysCollegeService.selectCollege(sysCollegeEntity);
    }
    //获取责任人
    @ApiOperation(value = "获取责任人", notes = "获取责任人")
    @PostMapping("/getCeachCode")
    public Result getCeachCode(){
        return sysCollegeService.getCeachCode();
    }
}

